package cn.tedu.cwfw.ser.controller;

import cn.tedu.cwfw.base.response.JsonResult;
import cn.tedu.cwfw.ser.pojo.dto.SerClassSaveParam;
import cn.tedu.cwfw.ser.pojo.vo.SerClassVO;
import cn.tedu.cwfw.ser.service.SerClassService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/cwfw/serviceClass")
@Slf4j
public class SerClassController {
    @Autowired
    SerClassService serClassService;
//    添加服务分类
    @PostMapping("/insert")
    public JsonResult insert (SerClassSaveParam serClassSaveParam){
        log.debug("添加服务分类:{}",serClassSaveParam);
        serClassService.insert(serClassSaveParam);
        return JsonResult.ok();
    }
//查看所有服务分类
    @GetMapping("selectAll")
    public JsonResult selectAll(){
        log.debug("查看所有服务分类");
        List<SerClassVO> serClassVOS = serClassService.selectAll();
        return JsonResult.ok(serClassVOS);
    }
//    根据id查看服务分类
    @GetMapping("/findById/{id}")
    public JsonResult findById(Long id){
        log.debug("根据id查看服务分类:{}",id);
        SerClassVO serClassVO = serClassService.findById(id);
        return JsonResult.ok(serClassVO);
    }
//    删除服务分类
    @PostMapping("/delete/{id}")
    public JsonResult delete(Long id){
        log.debug("删除服务分类:{}",id);
        serClassService.delete(id);
        return JsonResult.ok();
    }
}
